home *** CD-ROM | disk | FTP | other *** search
/ Mac Easy 2010 May / Mac Life Ubuntu.iso / casper / filesystem.squashfs / usr / share / pyshared / softwareproperties / gtk / DialogAdd.py < prev    next >
Encoding:
Python Source  |  2009-03-27  |  3.0 KB  |  85 lines

  1. # dialog_add.py.in - dialog to add a new repository
  2. #  
  3. #  Copyright (c) 2004-2005 Canonical
  4. #                2005 Michiel Sikkes
  5. #              
  6. #  Authors: 
  7. #       Michael Vogt <mvo@debian.org>
  8. #       Michiel Sikkes <michiels@gnome.org>
  9. #       Sebastian Heinlein <glatzor@ubuntu.com>
  10. #
  11. #  This program is free software; you can redistribute it and/or 
  12. #  modify it under the terms of the GNU General Public License as 
  13. #  published by the Free Software Foundation; either version 2 of the
  14. #  License, or (at your option) any later version.
  15. #  This program is distributed in the hope that it will be useful,
  16. #  but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  18. #  GNU General Public License for more details.
  19. #  You should have received a copy of the GNU General Public License
  20. #  along with this program; if not, write to the Free Software
  21. #  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
  22. #  USA
  23.  
  24. import os
  25. import gobject
  26. import gtk
  27. import gtk.glade
  28. from gettext import gettext as _
  29.  
  30. from aptsources.sourceslist import SourceEntry
  31.  
  32. class DialogAdd:
  33.   def __init__(self, parent, sourceslist, datadir, distro):
  34.     """
  35.     Initialize the dialog that allows to add a new source entering the
  36.     raw apt line
  37.     """
  38.     self.sourceslist = sourceslist
  39.     self.parent = parent
  40.     self.datadir = datadir
  41.     # gtk stuff
  42.     self.gladexml = gtk.glade.XML("%s/glade/dialogs.glade" % datadir)
  43.     self.dialog = self.gladexml.get_widget("dialog_add_custom")
  44.     self.dialog.set_transient_for(self.parent)
  45.     self.entry = self.gladexml.get_widget("entry_source_line")
  46.     self.button_add = self.gladexml.get_widget("button_add_source")
  47.     self.entry.connect("changed", self.check_line)
  48.     self.label_example_line = self.gladexml.get_widget("label_example_line")
  49.     # Create an example deb line from the currently used distro
  50.     if distro:
  51.         example = "%s %s %s %s" % (distro.binary_type,
  52.                                    distro.source_template.base_uri,
  53.                                    distro.codename,
  54.                                    distro.source_template.components[0].name)
  55.     else:
  56.         example = "deb http://ftp.debian.org sarge main"
  57.     # L10N: the example is of the format: deb http://ftp.debian.org sarge main
  58.     msg = _("The APT line includes the type, location and components of a "
  59.             "repository, for example  '%s'.") % ("<i>%s</i>" % example)
  60.     self.label_example_line.set_label(msg)
  61.  
  62.   def run(self):
  63.     res = self.dialog.run()
  64.     self.dialog.hide()
  65.     if res == gtk.RESPONSE_OK:
  66.         line = self.entry.get_text() + "\n"
  67.     else:
  68.         line = None
  69.     return line
  70.  
  71.   def check_line(self, *args):
  72.     """
  73.     Check for a valid apt line and set the sensitiveness of the
  74.     button 'add' accordingly
  75.     """
  76.     line = self.entry.get_text() + "\n"
  77.     source_entry = SourceEntry(line)
  78.     if source_entry.invalid == True or source_entry.disabled == True:
  79.         self.button_add.set_sensitive(False)
  80.     else:
  81.         self.button_add.set_sensitive(True)
  82.  
  83.